import json
from selenium import webdriver


class Driver:
    _driver = None

    @classmethod
    def get_login_driver(cls):
        if not cls._driver:
            cls._driver = webdriver.Edge()
            cls._driver.maximize_window()
            cls._driver.get('http://user-p2p-test.itheima.net/common/member/login')
        return cls._driver

    @classmethod
    def get_borrow_driver(cls):
        if not cls._driver:
            cls._driver = webdriver.Edge()
            cls._driver.maximize_window()
            cls._driver.get('http://user-p2p-test.itheima.net/loan/loan/loanview#?id=1')
        return cls._driver

    @classmethod
    def quit_login_driver(cls):
        if cls._driver:
            cls.get_login_driver().quit()
            cls._driver = None


def get_case_data(filename):
    """参数化文件内容获取"""
    with open(filename, encoding='utf-8') as f:
        case_data = json.load(f)
    data_li = []
    for case in case_data.values():
        data_li.append(tuple(case.values()))
    return data_li
